﻿[
	// Define the CMS type
	Define_Type: 'shp_CMS';
		
		Local:'pageid';
		Local:'title';
		Local:'content';
		Local:'pagetype';
		Local:'targetUrl';
		Local:'targetWindow';
		Local:'label';
		Local:'lang';
		Local:'langnr';
		Local:'Menutitle';
		Local:'MenuID';
		Local:'metakeywords';
		Local:'metadesc';
		Local:'MenuActive';


		Define_Tag:'oncreate';
		/Define_Tag;
		
		
		
	// *******************************************
	// ** PAGES                                 **
	// *******************************************

		Define_Tag:'getPage', -Required='page', -EncodeNone;
			Self->'pageid'= #page;

			var:'sql_pages'='	SELECT		*
								FROM 		SHb_pages
								INNER JOIN	SHb_translations_pages ON SHb_translations_pages._k2_pageid = SHb_pages._k1_pageid
								INNER JOIN	SHb_languages ON SHb_languages._k1_languageid = SHb_translations_pages._k2_languageid
								INNER JOIN	SHb_menus ON SHb_menus._k2_pageid = SHb_pages._k1_pageid
								INNER JOIN  SHb_translations_menus ON SHb_translations_menus._k2_menuid = SHb_menus._k1_menuid
								WHERE 		SHb_languages.language = \'' + $mylang + '\'';

			If:(#page)!='';
				$sql_pages+='	AND			SHb_pages._k1_pageid = \'' + (#page) +'\'';
			else;
				Self->'pageid'= 1;
				$sql_pages+='	AND			SHb_pages._k1_pageid = 1';
			/if;
			
			inline: -database='shoebox', -sql=$sql_pages;
				if:(found_count)!=0;
					local:'myTitle' = (field:'Page_title');
					local:'myContent' = (field:'Page_content');
					local:'myType' = (field:'_k2_pagetypeid');
					local:'myUrl' = (field:'target_url');
					local:'myTarget' = (field:'target_window');
					local:'myLabel' = (field:'label');
					local:'myMetaKeywords' = (field:'meta_keywords');
					local:'myMetaDesc' = (field:'meta_description');

				else;
					local:'myTitle' 		= 'Error: Page not found';
					local:'myContent' 		= '';
					local:'myType'			= '';
					local:'myUrl'			= '';
					local:'myTarget'		= '';
					local:'myLabel'			= '';
					local:'myMetaKeywords'	= '';
					local:'myMetaDesc'		= '';
				/if;
			/inline;
	
			Self->'title' 	     = #myTitle;
			Self->'content'      = #myContent;
			Self->'pagetype'     = #myType;
			Self->'targetUrl'    = #myUrl;
			Self->'targetWindow' = #myTarget;
			Self->'label'		 = #myLabel;
			Self->'metakeywords' = #myMetaKeywords;
			Self->'metadesc'	 = #myMetaDesc;

		/Define_Tag;
		
		Define_Tag:'CMSPageTitle';
			if:(Self->'pagetype') == 2;
				Return: Self->'label';
			else;
				Return: Self->'title';
			/if;
		/Define_Tag;
		
		Define_Tag:'CMSPageID'; 
			Return: Self->'pageid';
		/Define_Tag;
		
		Define_Tag:'CMSPageMetaKeywords'; 
			Return: Self->'metakeywords';
		/Define_Tag;
		
		Define_Tag:'CMSPageMetaDescription'; 
			Return: Self->'metadesc';
		/Define_Tag;
		
		
	// *******************************************
	// ** PAGES - TAB CONTENT                   **
	// *******************************************
			
		Define_Tag:'CMSPageContent';
			Local:'output' = '';
		
				#output += '<form id="pageform_save">';
				#output += '	<h2>'+($txt_title)+'</h2>';
				#output += '		<input type="text"   name="pagetitle" id="pageform_title" class="input_text" value="' + ($myCMS->CMSPageTitle()) + '" />';
				#output += '		<input type="hidden" name="langid"    id="pageform_lang"  value="' + ($myCMS->CMSLanguageID($mylang)) + '" />';
				#output += '		<input type="hidden" name="pageid"    id="pageform_page"  value="' + (encode_sql:(action_param:'p')) + '" />';
				#output += '		<input type="hidden" name="menuid"    id="pageform_menu"  value="' + ($myCMS->CMSMenuid((action_param:'p'))) + '" />';
		
			if:(Self->'pagetype')==2;
				#output += '<	h2>'+($txt_url)+'</h2>';
		    	#output += '		<input type="text" size="60" name="pagecontent" id="pageform_url" class="input_text" value="';
				#output += Self->'targetUrl'; //Self->'content';
				#output += '">';
				#output += '	<h2>'+($txt_openwindow)+'</h2>';
				#output += '		<input type="radio" name="pageform_target" id="pageform_target" value="_blank" ';
								if:(Self->'targetWindow') == '_blank';
									#output += 'checked';
								/if;
								#output += '> Blank<br />';
				#output += '		<input type="radio" name="pageform_target" id="pageform_target" value="_self" ';
								if:(Self->'targetWindow') == '_self';
									#output += 'checked';
								/if;
								#output += '> Self<br />';
				#output += '	<br /><br />';
				#output += '	<input type="button" name="saveurl" value="'+($txt_pagetype_button_save)+'" id="saveurl" />';
			else;
				#output += '	<h2>'+($txt_page)+'</h2>';
				#output += '		<textarea rows="30" cols="40" name="pagecontent" id="pageform_content">';
				#output += Self->'content';
				#output += '		</textarea>';
				#output += '	<br /><br />';
				#output += '	<input type="button" name="savepage" value="'+($txt_pagetype_button_save)+'" id="savepage" />';
			/if;
			
				#output += '</form><br />';
				
			Return(#output);
		/Define_Tag;
		
		
		
	// *******************************************
	// ** PAGES - TAB META-TAGS                 **
	// *******************************************
		
		Define_Tag:'CMSPageMetaTags';
			Local:'output' = '';
				#output += '<form id="metaform_save">';
				#output += '		<input type="hidden" name="langid" id="pageform_lang" value="' + ($myCMS->CMSLanguageID($mylang)) + '" />';
				#output += '		<input type="hidden" name="pageid" id="pageform_page" value="' + (encode_sql:(action_param:'p')) + '" />';
				#output += '	<h2>'+($txt_meta_desc)+'</h2>';
				#output += '		<textarea id="meta_description" name="meta_description" class="input_textarea">' + ($myCMS->CMSPageMetaDescription()) + '</textarea>';
				#output += '	<h2>'+($txt_meta_keywords)+'</h2>';
				#output += '		<textarea id="meta_keywords" name="meta_keywords" class="input_textarea">' + ($myCMS->CMSPageMetaKeywords()) + '</textarea>';
				#output += '	<br /><br />';
				#output += '	<input type="button" name="savemeta" value="'+($txt_pagetype_button_save)+'" id="savemeta" />';
				#output += '</form><br />';
			Return(#output);
		/Define_Tag;
		
	
	
	// *******************************************
	// ** PAGES - TAB BEHAVIOUR                 **
	// *******************************************
		
		Define_Tag:'CMSPageBehaviour';
			Local:'output' = '';
				#output += '<form id="behaviourform_save">';
				#output += '		<input type="hidden" name="langid" id="pageform_lang" value="' + ($myCMS->CMSLanguageID($mylang)) + '" />';
				#output += '		<input type="hidden" name="pageid" id="pageform_page" value="' + (encode_sql:(action_param:'p')) + '" />';
				#output += '	<h2>'+($txt_behaviour_title)+'</h2>';
				#output += '		<input type="checkbox" value="'+ ($myCMS->CMSMenuActive((encode_sql:(action_param:'p')))) + '" id="menu_active" name="menu_active" class="checkbox"';
					if:($myCMS->CMSMenuActive((encode_sql:(action_param:'p'))))==1;
						#output += ' checked ';
					/if;
				#output += '>';
				#output += '	' + ($txt_behaviour_desc) + '<br /><br />';
				#output += '	<input type="button" name="savebehaviour" value="'+($txt_pagetype_button_save)+'" id="savebehaviour" />';
				#output += '</form><br />';
			Return(#output);
		/Define_Tag;
		
		

	// *******************************************
	// ** MENUS                                 **
	// *******************************************
		
		Define_Tag:'getMenu', -Optional='menu', -EncodeNone;
			Local:'output' = '';

			var:'sql_menus'='	SELECT		*
            					FROM 		SHb_menus
            					INNER JOIN	SHb_translations_menus ON SHb_translations_menus._k2_menuid = SHb_menus._k1_menuid
            					INNER JOIN	SHb_languages ON SHb_languages._k1_languageid = SHb_translations_menus._k2_languageid
            					WHERE 		SHb_languages.language = \'' + $mylang + '\'
            					ORDER BY	SHb_menus._k2_parentid, SHb_menus._k2_levelid, SHb_menus._k1_menuid';

			inline: -database='shoebox', -sql=$sql_menus;
				if:(found_count)!=0;
					#output += '<ul>';
					Records;
						#output += '<li><a href="' + ($CMS_linkbaseurl) + '" target="' + (field:'target_window') + '">' + (field:'label') + '</a></li>';
					/Records;
					#output += '</ul>';
				/if;
			/inline;
			
			Return(#output);

		/Define_Tag;
		
	
	
		Define_Tag:'CMSMenuTitle', -required='page', -EncodeNone;
			var:'sql_gettitle'='SELECT		*
								FROM 		SHb_menus
								INNER JOIN	SHb_translations_menus ON SHb_translations_menus._k2_menuid = SHb_menus._k1_menuid
								INNER JOIN	SHb_languages ON SHb_languages._k1_languageid = SHb_translations_menus._k2_languageid
								WHERE 		SHb_menus._k2_pageid = \'' + (#page) +'\' ';
								// AND 		SHb_languages.language = \'' + $mylang + '\'
								

			inline: -database='shoebox', -sql=$sql_gettitle;
				if:(found_count)!=0;
					local:'myMenuTitle' = (field:'label');
				else;
					local:'myMenuTitle' = '';
				/if;
			/inline;
		
			Self->'Menutitle' = #myMenuTitle;
			Return: Self->'Menutitle';

		/Define_Tag;


		
		Define_Tag:'CMSMenuid', -required='page', -EncodeNone;
		
			Self->'pageid'= #page;

			If:(#page)!='';
				Self->'pageid'= #page;
			else;
				Self->'pageid'= 1;
			/if;
		
			var:'sql_getmenu_id'='	SELECT		*
									FROM 		SHb_menus
									INNER JOIN	SHb_translations_menus ON SHb_translations_menus._k2_menuid = SHb_menus._k1_menuid
									INNER JOIN	SHb_languages ON SHb_languages._k1_languageid = SHb_translations_menus._k2_languageid
									WHERE		SHb_menus._k2_pageid = \'' + (Self->'pageid') +'\' ';
									// AND 		SHb_languages.language = \'' + $mylang + '\'
			
			inline: -database='shoebox', -sql=$sql_getmenu_id;
				if:(found_count)!=0;
					local:'myMenuId'		= (field:'_k2_menuid');
					local:'myActiveMenu'	= (field:'active');

				else;
					local:'myMenuId'		= '';
					local:'myActiveMenu'	= '';
				/if;
			/inline;
		
			Self->'MenuID'		= #myMenuId;
			Self->'MenuActive'	= #myActiveMenu;

			Return: Self->'MenuID';

		/Define_Tag;
		
		
		Define_Tag:'CMSMenuActive'; 
			Return: Self->'MenuActive';
		/Define_Tag;
	
		
		
		
		
		
	// *******************************************
	// ** LANGUAGES                             **
	// *******************************************

		Define_Tag: 'getLang', -Optional='l', -EncodeNone;
				If:(#l)!='';
					var('language')=(#l);
				Else;
					var('language')=$CMS_defaultlanguage;
				/if;
			protect;
				include: $CMS_site_path + 'includes/' + $CMS_defaultlanguage + '.lasso';
			/protect;
		/Define_Tag;
		
		
		Define_Tag: 'CMSLanguageID', -optional='l', -EncodeNone;
				If:(#l)!='';
					var('language_chosen')=(#l);
				Else;
					var('language_chosen')=$CMS_defaultlanguage;
				/if;
				
				inline: -database='shoebox', -sql='SELECT * FROM SHb_languages WHERE language = \'' + (var:'language_chosen') + '\'';
					if:(found_count)==0;
						Self->'langnr' = '1';
					else;
						Self->'langnr' = (field:'_k1_languageid');
					/if;
				/inline;
				
			Return: Self->'langnr';
		/Define_Tag;
		
		
		Define_Tag: 'getLangNav', -optional='l', -EncodeNone;
				inline: -database='shoebox', -sql='SELECT * FROM SHb_languages';
					var:'taallijst'=(array);
					if:(error_currenterror:-errorcode)==0;
						Records;
							$taallijst->(Insert:(field:'language'));
						/Records;
					/if;
				/inline;
			
				Local:'taallijst' = $taallijst;
				Local:'currentlang' = (var:'language');
				Local:'output' = '';
				#output += '<ul id="nav_1" class="nav_level_1">';
				iterate: (#taallijst), (var:'thislang');
					#output += '<li>';
					if:($thislang)==(#currentlang);
						#output += '<a href="' + ($CMS_linkbaseurl) + '?l=' + $thislang + '" class="current" id=\"dontShow\">';
					else;
						#output += '<a href="' + ($CMS_linkbaseurl) + '?l=' + $thislang + '" id=\"dontShow\">';
					/if;
					#output += $thislang;
					#output += '</a></li>';
				/iterate;
				#output += '</ul>';
				Return(#output);
		/Define_Tag;
		
		
		
		
		
	// *******************************************
	// ** TREE                                  **
	// *******************************************
		
		
		Define_Tag:'getTree', -EncodeNone;
			Local:'output' = '';
    		Local:'lang'=(encode_sql:(action_param:'l'));
			
			#output += '<ul id="tree">';
           						Records: -InlineName='Get_home_menu';
            #output += '			<li><a href="' +(Response_FilePath) + '?p=' + (field:'_k2_pageid') + '&l=' $mylang + '" id=\"dontShow\">' + (field:'label');
									if:(field:'active')!=1;
										#output += '</a> <img src="images/inactive.gif" border="0" align="absmiddle" title="' + ($txt_menu_inactive_tooltip) + '"></li>';
									else;
										#output += '</a></li>';
									/if;
								/Records;
								Records: -InlineName='Get_top_menus';
			#output += '			<li><a href="' + (Response_FilePath) +'?p=' + (field:'_k2_pageid') + '&l=' + $mylang + '" id=\"' + (field:'_k2_pageid') + '\" lang=\"' + $mylang + '\" langId=\"' + ($myCMS->CMSLanguageID($mylang)) + '" menuId="' + (field:'_k1_menuid') + '">' + (field:'label');
			
										if:(field:'active')!=1;
											#output += '</a> <img src="images/inactive.gif" border="0" align="absmiddle" title="' + ($txt_menu_inactive_tooltip) + '">';
										else;
											#output += '</a>';
										/if;
			
										var:'current_menu_id'=(field:'_k1_menuid');
			   							var:'sql_sub_menus'='
											SELECT		*
											FROM 		SHb_menus
											INNER JOIN	SHb_translations_menus ON SHb_translations_menus._k2_menuid = SHb_menus._k1_menuid
											INNER JOIN	SHb_languages ON SHb_languages._k1_languageid = SHb_translations_menus._k2_languageid
											WHERE 		SHb_languages.language = \'' + $mylang + '\'';
			$sql_sub_menus += '				AND			SHb_menus._k2_parentid = \'' + $current_menu_id + '\'';
			$sql_sub_menus += '				ORDER BY	SHb_menus._k2_parentid, SHb_menus._k1_menuid';
										Inline: -database='SHoebox', -sql=$sql_sub_menus;
											if:(found_count)!=0;
			#output += '						<ul>';
													Records;
			#output += '								<li><a href="' + (Response_FilePath) + '?p=' + (field:'_k2_pageid') + '&l=' + $mylang + '" id=\"' + (field:'_k2_pageid') + '\" lang=\"' + $mylang + '\" langId=\"' + ($myCMS->CMSLanguageID($mylang)) + '" menuId="' + (field:'_k1_menuid') + '">' + (field:'label');
															if:(field:'active')!=1;
																#output += '</a> <img src="images/inactive.gif" border="0" align="absmiddle" title="' + ($txt_menu_inactive_tooltip) + '"></li>';
															else;
																#output += '</a></li>';
															/if;
													/Records;
			#output += '						</ul>';
											/if;
			 							/Inline;
			#output += '			</li>';
								/Records;
			#output += '	</ul>';
			#output += '	<br /><br />';
			
			#output += '	<div class="contextMenu" id="contextMenu">';
			#output += '		<ul>';
			#output += '			<li><a href="#" id="ModalRename">' + ($txt_context_rename) + '</a></li>';
			#output += '			<li><a href="#" id="ModalDelete">' + ($txt_context_delete) + '</a></li>';
			#output += '		</ul>';
			#output += '	</div>';
			
			#output += '	<div id="RenameModalContent" style="display:none">';
            #output += '		<h1>' + ($txt_context_rename) + '</h1>';
			#output += '		<p id="rename_desc">' + ($txt_modal_rename_desc) + '</p>';
			#output += '		<form id="rename_title">';
			#output += '			<input type="text"   name="title" 			id="menuform_title" value="' + ($myCMS->CMSMenuTitle((encode_sql:(action_param:'pa')))) + '" />';
			#output += '			<input type="hidden" name="langid"			id="menuform_lang"  value="' + ($myCMS->CMSLanguageID(#lang)) + '" />';
			#output += '			<input type="hidden" name="menuid"			id="menuform_menu"  value="' + ($myCMS->CMSMenuid((encode_sql:(action_param:'pa')))) + '" />';
			#output += '			<input type="button" name="rename_submit"	id="rename_submit"	value="' + ($txt_context_rename) + '" />';
			#output += '		</form>';
			#output += '		<br />';
			#output += '		<div id="rename_title_msg"></div>';
			#output += '	</div>';
			
			#output += '	<div id="DeleteModalContent" style="display:none">';
			#output += '		<h1>' + ($txt_context_delete) + '</h1>';
			#output += '		<p id="delete_desc">' + ($txt_modal_delete_desc) + '</p>';
			#output += '		<form id="delete_title">';
			#output += '			<input type="hidden" name="langid"			id="menuform_lang"  value="' + ($myCMS->CMSLanguageID(#lang)) + '" />';
			#output += '			<input type="hidden" name="menuid"			id="menuform_menu"  value="' + ($myCMS->CMSMenuid((encode_sql:(action_param:'pa')))) + '" />';
			#output += '			<input type="button" name="delete_submit"	id="delete_submit"	value="' + ($txt_context_delete) + '" />';
			#output += '		</form>';
			#output += '		<br />';
			#output += '		<div id="delete_title_msg"></div>';
			#output += '	</div>';

			Return(#output);

		/Define_Tag;
	
	
	
		
		
	/Define_Type;
]